package com.own.business.system.menu.controller.manage;

import com.own.aop.permission.PermissionModule;
import com.own.aop.permission.PermissionOperation;
import com.own.business.system.menu.business.service.SystemUserRoleService;
import com.own.business.system.menu.common.constant.ConstantModule;
import com.own.business.system.menu.entity.dto.SystemUserRoleDto;
import com.own.business.system.menu.entity.map.SystemUserRoleMapVo;
import com.own.business.system.menu.entity.query.SystemUserRoleQuery;
import com.own.business.system.menu.entity.vo.SystemUserRoleVo;
import com.own.component.common.base.controller.BaseController;
import com.own.component.common.model.PageModel;
import com.own.component.common.model.R;
import com.own.component.common.model.ResultModel;
import com.own.component.log.operation.aop.LogOperationAop;
import com.own.component.store.core.confirm.aop.ConfirmAop;
import com.own.constant.ConstantApiPrefix;
import com.own.constant.ConstantBeanSuffix;
import com.own.constant.ConstantPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * ManageSystemUserRoleController
 *
 * @author chenxueli
 * @date 2024-03-31 10:00:18
 */
@Tag(name = "系统用户角色" + ConstantBeanSuffix.MANAGE_CLIENT + ConstantBeanSuffix.CONTROLLER)
@PermissionModule(ConstantModule.USER_ROLE)
@RestController
@RequestMapping(ConstantApiPrefix.BASE_API_V1_PREFIX + ConstantApiPrefix.MANAGE_CLIENT + "system/user/role")
public class ManageSystemUserRoleController extends BaseController {

    @Resource
    private SystemUserRoleService systemUserRoleService;

    @LogOperationAop
    @PermissionOperation(ConstantPermission.SEARCH)
    @Operation(summary = "查询所有信息")
    @PostMapping("/all")
    public ResultModel<List<SystemUserRoleVo>> all(
            @RequestBody SystemUserRoleQuery query
    ) {
        var list = systemUserRoleService.all(query);
        return R.success(list);
    }

    @LogOperationAop
    @PermissionOperation(ConstantPermission.SEARCH)
    @Operation(summary = "分页查询信息")
    @PostMapping("/page")
    public ResultModel<PageModel<SystemUserRoleVo>> page(
            @RequestBody SystemUserRoleQuery query
    ) {
        var pageModel = systemUserRoleService.page(query);
        return R.success(pageModel);
    }

    @LogOperationAop
    @PermissionOperation(ConstantPermission.SEARCH)
    @Operation(summary = "map查询信息")
    @PostMapping("/map")
    public ResultModel<List<SystemUserRoleMapVo>> map(
            @RequestBody SystemUserRoleQuery query
    ) {
        var list = systemUserRoleService.map(query);
        return R.success(list);
    }

    @LogOperationAop
    @PermissionOperation(ConstantPermission.ADD)
    @Operation(summary = "添加信息")
    @PostMapping("/")
    public ResultModel<SystemUserRoleVo> add(
            @Validated @RequestBody SystemUserRoleDto dto
    ) {
        dto.check();
        var updateModel = systemUserRoleService.add(dto.toBo());
        return R.success(updateModel);
    }

    @LogOperationAop
    @PermissionOperation(ConstantPermission.UPDATE)
    @Operation(summary = "修改信息")
    @PutMapping("/{systemUserRoleId}")
    public ResultModel<SystemUserRoleVo> update(
            @Parameter(description = "主键id", required = true) @PathVariable Long systemUserRoleId,
            @Validated @RequestBody SystemUserRoleDto dto
    ) {
        dto.check();
        var updateModel = systemUserRoleService.update(systemUserRoleId, dto.toBo());
        return R.success(updateModel);
    }

    @LogOperationAop
    @PermissionOperation(ConstantPermission.DELETE)
    @ConfirmAop(message = "确认删除该项目？（注意：删除之后无法找回数据，且该项目所有资料会被删除）")
    @Operation(summary = "删除信息")
    @DeleteMapping("/{systemUserRoleId}")
    public ResultModel<Boolean> delete(
            @Parameter(description = "主键id", required = true) @PathVariable Long systemUserRoleId
    ) {
        var updateModel = systemUserRoleService.delete(systemUserRoleId);
        return R.success(updateModel);
    }

    @LogOperationAop
    @PermissionOperation(ConstantPermission.VIEW)
    @Operation(summary = "根据id获取信息")
    @GetMapping("/{systemUserRoleId}")
    public ResultModel<SystemUserRoleVo> getById(
            @Parameter(description = "主键id", required = true) @PathVariable Long systemUserRoleId
    ) {
        var vo = systemUserRoleService.getById(systemUserRoleId);
        return R.success(vo);
    }

}
